package com.surprise.db.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.surprise.db.entity.Mall;

/**
 * MallRepository.java
 * @author nick
 * @since 2016年1月11日
**/
public interface MallRepository extends JpaRepository<Mall, Long> {
	@PersistenceContext
	public EntityManager em=null;
	
	@Query("select o from mall o where o.name like %?1%") 
	public List<Mall> query(String name,Pageable pageable);
	
	@Query("select o from mall o where o.districtid = ?1") 
	public List<Mall> queryMallBydistrictid(long districtid);

	public List<Mall> findByNameAndCityid(String name,long cityid);

	Page<Mall> findAll(Specification<Mall> spec, Pageable pageable);  //分页按条件查询  
	  
	List<Mall> findAll(Specification<Mall> spec);    //不分页按条件查询 
	
	@Query("select o from mall o where o.districtid = ?1") 
	public List<Mall> findMallByUserid(long userid);

}
